import { User } from 'src/user/entities/user.entity';
import {
    Column,
    CreateDateColumn,
    Entity,
    JoinColumn,
    ManyToOne,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
} from 'typeorm';

// Entity 装饰器  定义实体

@Entity('logs')
export class Logs {
    @PrimaryGeneratedColumn('uuid') // 设置主键
    id: string;

    @Column({
        type: 'varchar',
        length: 255,
        comment: 'path',
    })
    path: string;

    @Column({
        type: 'varchar',
        length: 255,
        comment: 'methods',
    })
    methods: string;

    @Column({
        type: 'varchar',
        length: 255,
        comment: 'data',
    })
    data: string;

    @Column({
        type: 'int',
        comment: 'code状态码',
    })
    code: string;

    @CreateDateColumn()
    createdAt: Date;

    @UpdateDateColumn()
    updatedAt: Date;

    // 外键约束  和日志表和user表的关系 是  一个用户可以对应多个日志
    @ManyToOne(() => User, (user) => user.logs)
    
    // @JoinColumn装饰器  通常和@ManyToOne 或 @OneToOne 关联
    // 用于在实体之间建立关系
    @JoinColumn() // JoinColumn 会自动创建userId字段
    user: User;

}
